import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index'

Vue.use(Router)

const router = new Router({
    mode: 'hash',
    routes: [{
      path:'/',
      redirect:'/login'
    },{
      path:'/login',
      name:'login',
      component:()=> import('@/view/login/logins')
    },{
      path:'/main',
      name:'mainstay',
      component:()=> import('@/view/main/mains'),
    }]
})

router.beforeEach((to, from, next) => {
  if (to.name === 'login' || store.state.user.token) {
    next();
  } else {
    router.push('/login');
  }
})

export default router